﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using PeonyShop.Class;
using PenoyShop.Utilities;

namespace PeonyShop.DAL
{
    public class DAProduct : BaseDA
    {
        public DAProduct()
        {

        }

        public DataSet GetAllProductById(int Id)
        {
            DataSet ds = new DataSet();
            //DbCommand cmd = DB.GetSqlStringCommand("select * from UnitType");
            DbCommand cmd = DB.GetStoredProcCommand("sp_GetAllUnitype");
            ds = DB.ExecuteDataSet(cmd);
            return ds;
        }

        public bool Insert(CProduct oProduct)
        {
            return true;

        }

        public bool Edit(CProduct oProduct)
        {
            return false;
        }

        public bool Delete(int Id)
        {
            return false;

        }

        public DataSet GetProductById(int Id)
        {
            DataSet ds = new DataSet();
            return ds;
        }

        public DataSet GetProductByCate(int MainCate, int SubCate)
        {
            DataSet ds = new DataSet();
            try
            {
                DbCommand cmd = DB.GetStoredProcCommand("sp_GetProductByCate");
                DB.AddInParameter(cmd, "@Cate", SqlDbType.Int, MainCate);
                if (SubCate != -1)
                    DB.AddInParameter(cmd, "@SubCate", SqlDbType.Int, SubCate);
                ds = DB.ExecuteDataSet(cmd);
            }
            catch (Exception ex)
            {
                Logger.FrameworkLogger.Error("GetProductByCate ", ex);
                ds = null;
            }
            return ds;
        }
    }
}
